package auth;

import beans.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class AuthorizationServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        getServletContext().getRequestDispatcher("/authorization.html").include(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String login = req.getParameter("login");
        String pass = req.getParameter("pass");
        Authorisation authObject = new Authorisation(getServletContext());
        if (authObject.avtorization(login,pass)){
            User user = authObject.getUser();
            getServletContext().getRequestDispatcher("user_cab.html").include(req, resp);
        }else{
            resp.sendRedirect("/authorization.html");
        }

    }
}
